//
//  HotViewController.m
//  HaoHaiSpell
//
//  Created by haohai on 16/6/17.
//  Copyright © 2016年 海城. All rights reserved.
//

#import "HotViewController.h"
#import "HomepageCell.h"
#import "FourthSectionCell.h"

@interface HotViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

<<<<<<< HEAD
@property (strong, nonatomic) UICollectionView *hotCollectionView;
@property (nonatomic,strong) NSMutableArray *allDataArray;
@property (nonatomic,strong) NSMutableDictionary *parameter;
@property (nonatomic,strong) NSArray *titleArr;
@property (nonatomic,strong) UILabel *markLabel;
@property (nonatomic,strong) UIButton *selebtn;//选中按钮

@end

@implementation HotViewController
#pragma mark - 懒加载

-(UICollectionView *)hotCollectionView{

    if (!_hotCollectionView) {
        // 集合视图布局
        UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
        layout.minimumLineSpacing=10;
        layout.minimumInteritemSpacing=10;
        layout.sectionInset=UIEdgeInsetsMake(10, 10, 10, 10);
        //      layout.itemSize=CGSizeMake(kWidth-20, (kHeight-30)/3);
        _hotCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 101, kWidth, kHeight - 101) collectionViewLayout:layout];
        _hotCollectionView.backgroundColor = HWColor(241, 241, 241);
        _hotCollectionView.delegate = self;
        _hotCollectionView.dataSource = self;
    }
    return _hotCollectionView;
}

-(NSArray *)titleArr{

    if (!_titleArr) {
        _titleArr = @[@"热门拼团",@"热门精品"];
    }
    return _titleArr;
}

-(NSMutableArray *)allDataArray{

    if (!_allDataArray) {
        _allDataArray = [NSMutableArray new];
    }
    return _allDataArray;
}

-(NSMutableDictionary *)parameter{

    if (!_parameter) {
        _parameter = [NSMutableDictionary dictionaryWithDictionary:@{@"":@""}];
    }
    return _parameter;
}

#pragma mark - 自定义
-(void)createView{

    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, kWidth, 37)];
    UIButton *teamBtn =[self createButtonWithFrame:CGRectMake(0, 0, kWidth / 2 - 2, 35) title:@"热门拼团" slector:@selector(teamAction:) image:nil];
    teamBtn.backgroundColor = [UIColor whiteColor];
    [teamBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIButton *shoppingBtn = [self createButtonWithFrame:CGRectMake(kWidth / 2 , 0, kWidth / 2 - 2, 35) title:@"热门精品" slector:@selector(shoppingAction:) image:nil];
    [shoppingBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    shoppingBtn.backgroundColor = [UIColor whiteColor];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(kWidth / 2 - 2,0, 2, 35)];
    self.markLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 35, kWidth / 2 - 2, 2)];
    self.markLabel.backgroundColor = [UIColor redColor];
    
    view.backgroundColor = [UIColor lightGrayColor];
    [headView addSubview:view];
    [headView addSubview:teamBtn];
    [headView addSubview:shoppingBtn];
    [headView addSubview:self.markLabel];
    [self.view addSubview:headView];
}


-(UIButton *)createButtonWithFrame:(CGRect)frame title:(NSString *)title slector:(SEL)selector image:(UIImage *)btImage{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    [btn setImage:btImage forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setFrame:frame];
    [btn addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

-(void)selBtnAction:(UIButton *)button{
    
    //设置偏移及字体颜色
    [self.selebtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.selebtn .transform = CGAffineTransformIdentity;
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [UIView animateWithDuration:0.3
                     animations:^{
                         
                         CGPoint point = self.markLabel.center;
                         point.x = button.center.x;
                         self.markLabel.center = point;
                     }];
    self.selebtn = button;
}


-(void)teamAction:(UIButton *)sender{


    [self selBtnAction:sender];
    NSLog(@"热门拼团");
}

-(void)shoppingAction:(UIButton *)sender{
    
   [self selBtnAction:sender];
  NSLog(@"热门精品");
}
#pragma mark - 视图生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = HWColor(241, 241, 241);
    [self createView];
    [self.view addSubview:self.hotCollectionView];
=======
@property (weak, nonatomic) IBOutlet UIView *sgementView;
@property (weak, nonatomic) IBOutlet UICollectionView *hotCollectionView;





@end

@implementation HotViewController


#pragma mark - 视图生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    // 集合视图布局
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    layout.minimumLineSpacing=10;
    layout.minimumInteritemSpacing=10;
    layout.sectionInset=UIEdgeInsetsMake(10, 10, 10, 10);
    //      layout.itemSize=CGSizeMake(kWidth-20, (kHeight-30)/3);
    self.hotCollectionView.collectionViewLayout = layout;
    
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
    [self.hotCollectionView registerNib:[UINib nibWithNibName:@"HomepageCell" bundle:nil] forCellWithReuseIdentifier:@"HomepageCell"];
    [self.hotCollectionView registerNib:[UINib nibWithNibName:@"FourthSectionCell" bundle:nil] forCellWithReuseIdentifier:@"fourthCell"];
  
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - UICollectionViewDataSource,UICollectionViewDelegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{


    return 10;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    HomepageCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"HomepageCell" forIndexPath:indexPath];
    
    return cell;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

<<<<<<< HEAD
    return CGSizeMake(kWidth - 20, (kHeight - 101) / 4);
=======
    return CGSizeMake(kWidth, kHeight / 4);
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
}

@end
